package ws.mybatis;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import ws.mybatis.Entity.Blog;
import ws.mybatis.mapper.BlogMapper;

public class myBatisTest {
	
	public static void  getSqlSessionFactory() throws IOException{
		String resource = "MyBatis.xml";
		InputStream inputStream = Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		SqlSession session = sqlSessionFactory.openSession();
	    try {
		  BlogMapper mapper = session.getMapper(BlogMapper.class);
		  Blog blog = mapper.selectBlog(1);
		  System.out.println(blog.getName());
		  System.out.println(blog.getCreateTime());
		} finally {
		  session.close();
		}
	}
	
	public static void main(String[] args) throws IOException {
		getSqlSessionFactory();
	}

}
